package com.bw.controller;

import com.bw.entity.Zzt;
import com.bw.mapper.ZztMapper;
import org.spring.kun.common.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
//@RestController// 默认给所有的方法加上@ResponseBody
public class ZztController {

    @Autowired
    ZztMapper zztMapper;

    /**
     * 报表页面
     * @return
     */
    @RequestMapping("/tuPage.do")
    public String tu() {

        return "tu";
    }

    /**
     * 点击展示图表 获取图表需要的数据
     * @param status
     * @return
     */
    @RequestMapping("/zzt.do")
    @ResponseBody  //返回值不再是一个页面了，而是真实的数据 （Json格式的）
    public List<Zzt> zzt(String status) {

        List<Zzt> list = zztMapper.zzt(status);
        return list;
    }

    /**
     * 执行Excel 导出
     * @param status
     */
    @RequestMapping("/excelTu.do")
    public void  excelTu(String status, HttpServletResponse response) {

        List<Zzt> list = zztMapper.zzt(status);

        ExcelUtils.exportExcel(list,"楼盘数据导出","sheet1",response);

    }
}
